package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/9/7 10:01
 * @description 495. 提莫攻击
 */
public class Test495 {
    public static void main(String[] args) {
        int poisonedDuration = findPoisonedDuration(new int[]{1, 2}, 2);
        System.out.println(poisonedDuration);
    }

    // 1次过
    public static int findPoisonedDuration(int[] timeSeries, int duration) {

        int count = 0;
        for (int i = 1; i < timeSeries.length; i++) {

//            if (timeSeries[i] - timeSeries[i - 1] < duration) {
//                count += timeSeries[i] - timeSeries[i - 1];
//            } else {
//                count += duration;
//            }

            count += Math.min(timeSeries[i] - timeSeries[i - 1], duration);
        }
        return count + duration;
    }
}
